package com.qf.day06;

public class Fish extends Animal implements Comparable<Fish>{
    private String breathe;//呼吸方式
    public void swim(){
        System.out.println(getName()+"在游泳");
    }

    public Fish() {
    }

    public Fish(String name, String type, int age, String sex, String breathe) {
        super(name, type, age, sex);
        this.breathe = breathe;
    }

    public String getBreathe() {
        return breathe;
    }

    public void setBreathe(String breathe) {
        this.breathe = breathe;
    }

    @Override
    public int compareTo(Fish o) {
        //获取当前鱼的年龄
        int age = this.getAge();
        //获取要比较的鱼的年龄
        int targetAge = o.getAge();
        if(age==targetAge){
            String name = this.getName();
            String targetName = o.getName();
            return name.length()-targetName.length();
        }
        return age - targetAge;
    }

        @Override
    public String toString() {
        return "Fish{" +"name='" + getName() + '\'' +
                ", type='" + getType() + '\'' +
                ", age=" + getAge() +
                ", sex='" + getSex() + '\''+
                ",breathe='" + breathe + '\'' +
                "} " ;
    }
}
